package com.zh.edu.info.manager.dao;

import com.zh.edu.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teacher = new Teacher[5];
    public Teacher[] arrFind() {
        return teacher;
    }

    public void addTeacher(Teacher teacher) {
        for (int i = 0; i < this.teacher.length; i++) {
            if (this.teacher[i] == null) {
                this.teacher[i] = teacher;
                break;
            }
        }
    }

    private int indexFind(String id) {
        int index = -1;
        for (int i = 0; i < teacher.length; i++) {
            if (teacher[i] != null && teacher[i].getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void selectTeacher(String id) {
        int index = indexFind(id);
        teacher[index] = null;
    }

    public void updateTeacher(String id, Teacher teacher) {
        int index = indexFind(id);
        this.teacher[index] = teacher;
    }
}
